<script setup>
import axios from "axios";
import EZUIKit from "ezuikit-js";
import { nextTick, ref } from "vue";
const player = ref(null);
const popup = ref(null);
function open() {
  popup.value.open();
  nextTick(() => {
    initPlayer();
  });
}
function initPlayer() {
  new EZUIKit.EZUIKitPlayer({
    id: "video-container",
    accessToken: localStorage.getItem("openToken") || "123",
    url: "ezopen://open.ys7.com/FT5342207/1.live",
    template: "simple", // simple - 极简版;standard-标准版;security - 安防版(预览回放);voice-语音版；
    audio: 0, // 是否默认开启声音 0 - 关闭 1 - 开启
    width: 1460,
    height: 770,
    handleError: (err) => {
      console.log(err);

      if (err.code === "10002") {
        axios
          .post(
            "https://open.ys7.com/api/lapp/token/get?appKey=5c39de74a73640b4b4cee4155a62c3f3&appSecret=65bc32a591637b42baf50dc27827b24f"
          )
          .then((res) => {
            console.log(res);

            localStorage.setItem("openToken", res.data.data.accessToken);
            initPlayer();
          });
      }
    },
  });
}
defineExpose({ open });
</script>

<template>
  <Popup width="1600" height="928" ref="popup" title="智慧茶园监控">
    <div id="video-container"></div>
  </Popup>
</template>

<style lang="scss" scoped></style>
